package service

import (
	sqlc "bgs/db/sqlc"
	"context"
)

func (s *LedgerServiceImp) ListLedgerDetailsByOrderSerialNumber(ctx context.Context, q *sqlc.Queries, orderSerialNumber string) (ptrs []*sqlc.LedgerDetail, err error) {
	ledgerDetails, err := q.ListLedgerDetailsByOrderSerialNumber(ctx, orderSerialNumber)
	if err != nil {
		return
	}
	ptrs = s.ConvLedgerDetailEntitiesToPtrs(ledgerDetails)
	return
}

func (s *LedgerServiceImp) ListLedgerDetailsByRequestID(ctx context.Context, q *sqlc.Queries, ledgerRequestID int64) (ptrs []*sqlc.LedgerDetail, err error) {
	ledgerDetails, err := q.ListLedgerDetailsByRequestID(ctx, sqlc.NInt64FromInt64(ledgerRequestID))
	if err != nil {
		return
	}
	ptrs = s.ConvLedgerDetailEntitiesToPtrs(ledgerDetails)
	return
}

func (s *LedgerServiceImp) ListLedgerDetailsByRollbackID(ctx context.Context, q *sqlc.Queries, ledgerRollbackID int64) (ptrs []*sqlc.LedgerDetail, err error) {
	ledgerDetails, err := q.ListLedgerDetailsByRollbackID(ctx, sqlc.NInt64FromInt64(ledgerRollbackID))
	if err != nil {
		return
	}
	ptrs = s.ConvLedgerDetailEntitiesToPtrs(ledgerDetails)
	return
}

func (s *LedgerServiceImp) ListLedgerDetailsAtAfterSaleDeadlineByOrderIDWithLock(ctx context.Context, q *sqlc.Queries, orderID int64) (ptrs []*sqlc.LedgerDetail, err error) {
	ledgerDetails, err := q.ListLedgerDetailsAtAfterSaleDeadlineByOrderIDToLock(ctx, orderID)
	if err != nil {
		return
	}
	ptrs = s.ConvLedgerDetailEntitiesToPtrs(ledgerDetails)
	return
}
